<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>


    <script>
        //构造的方式创建对象


        // console.log(this)

        // function Person() {
        //     this.name = "tom";
        //     this.age = 20;
        //     this.say = function() {
        //         alert("hello")
        //     }

        // }

        // //创建对象
        // var p = new Person();

        // console.log(p.name)
        // p.say()


        //带参的构造
        // function Car(name, color, run) {
        //     this.name = name;
        //     this.color = color;
        //     this.run = run;
        // }

        // var c = new Car("保时捷", "银色", function() {
        //     alert(c.name + ":" + c.color)
        // })

        // console.log(c.name)
        // c.run();

        //es6创建对象

        class User {

            constructor(name, pwd) {

                this.name = name;
                this.pwd = pwd;
            }

            showName() {
                alert("方法一")
            }

            showPwd() {
                alert("方法二")

            }
        }

        var u = new User("嘿嘿", "123456")
        console.log(u.name)

        u.showName();
    </script>
</body>

</html>